<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout" layout:decorator="base/layout.html">
<head>
    <title>修改房屋信息</title>
</head>
<body>
    <!-- start: Content -->
    <div layout:fragment="content" class="main">
        <div class="row">
            <div class="col-lg-12">
                <ol class="breadcrumb">
                    <li><i class="fa fa-home"></i><a href="index.html">主页</a></li>
                    <li><i class="fa fa-list-alt"></i><a href="#">房屋管理</a></li>
                    <li><i class="fa fa-indent"></i>修改房屋信息</li>
                </ol>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h2><i class="fa fa-indent red"></i><strong>修改房屋信息</strong></h2>
                    </div>
                    <form id="modularForm" action="/house/update" method="post" enctype="multipart/form-data" class="form-horizontal">
                        <div class="panel-body">
                            <input type="hidden" name="id" th:value="${house.id}" />
                            <div class="form-group">
                                <label class="col-md-3 control-label">地址</label>
                                <div class="col-md-9">
                                    <input type="text" name="address" class="form-control" th:value="${house.address}" required>
                                    <span class="help-block">请输入地址</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label">房产证号</label>
                                <div class="col-md-9">
                                    <input type="text" name="houseNumber" class="form-control" th:value="${house.houseNumber}" required>
                                    <span class="help-block">请输入房产证号</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label">户型</label>
                                <div class="col-md-9">
                                    <input type="text" name="flooPlan" class="form-control" th:value="${house.flooPlan}" required>
                                    <span class="help-block">请输入户型</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label">面积</label>
                                <div class="col-md-9">
                                    <input type="number" name="area" class="form-control" th:value="${house.area}" required>
                                    <span class="help-block">请输入面积（平方米）</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label">建造年份</label>
                                <div class="col-md-9">
                                    <input type="number" name="buildYear" class="form-control" th:value="${house.buildYear}" required>
                                    <span class="help-block">请输入建造年份</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-md-3 control-label">产权类型</label>
                                <div class="col-md-9">
                                    <input type="text" name="propertyType" class="form-control" th:value="${house.propertyType}" required>
                                    <span class="help-block">请输入产权类型</span>
                                </div>
                            </div>
                        </div>
                        <div class="panel-footer">
                            <button id="submitBtn" type="button" class="btn btn-sm btn-success"><i class="fa fa-dot-circle-o"></i> 保存</button>
                            <button type="button" class="btn btn-sm btn-success" onclick="history.back()"><i class="fa fa-dot-circle-o"></i> 返回</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <script th:inline="javascript">
            $(document).ready(function() {
                $("#submitBtn").click(function () {
                    // 表单验证
                    if (!$("#modularForm")[0].checkValidity()) {
                        $("#modularForm")[0].reportValidity();
                        return;
                    }

                    $.ajax({
                        url: 'update',
                        type: 'post',
                        data: $('#modularForm').serialize(),
                        success: function (data) {
                            layer.msg("修改成功");
                            setTimeout(function () {
                                window.location.href = "house";
                            }, 1500);
                        },
                        error: function(xhr, status, error) {
                            layer.msg("修改失败：" + error);
                        }
                    });
                });
            });
        </script>
    </div>
    <!-- end: Content -->
</body>
</html>

